#include <iostream>
#include <stdlib.h>

using namespace std;

struct Node
{
    int data;
    Node* next;
};

struct Stack
{
    Node* top;
    int count;
};

Stack* creat_stack()
{
    Stack* p;
    p=(Stack* )malloc(sizeof(Stack));
    if(p==NULL)
    {
        cout<<"error there is no enough story"<<endl;
        exit(0);
    }
    p->count=0;
    p->top=NULL;
    return p;
}

Stack* push_stack(Stack* p,int data)
{
    if (p==NULL) return NULL;
    Node *temp;
    temp=(Node*)malloc(sizeof(Node));
    temp->data=data;
    temp->next=p->top;
    p->top=temp;
    p->count++;
    return p;
}

Stack* pop(Stack* p)
{
    Node *temp;
    temp=p->top;
    if(p->top==NULL)
    {
        cout<<"error , there is no enough story";
        return p;
    }
    else
    {
        p->top=p->top->next;
        free(temp);
        p->count--;
        return p;
    }
}

int display(Stack* p)
{
    Node* temp;
    temp=p->top;
    if(p->top=NULL)
    {
        cout<<"there is error"<<endl;
        return 0;
    }
    while(temp!=NULL)
    {
        cout<<temp->data;
        temp=temp->next;
    }
    cout<<endl;
    return 0;
}

int main()
{
    Stack* p;
    p=creat_stack();
    int n=5;
    int input[6]={10,20,30,40,50,60};

    for(int i=0;i<n;i++)
    {
        push_stack(p, input[i]);
    }

    display(p);
    pop(p);
    display(p);
    
    system("pause");
    return 0;
}




